from datetime import datetime

from django.db import models

from django.contrib.auth.models import AbstractUser


# Create your models here.


class UserProfile(AbstractUser):
    """
    用户
    """
    GENDER_CHOICES = (
        (1, "男"),
        (2, "女")
    )
    name = models.CharField(verbose_name="姓名", max_length=30, null=True, blank=True)
    birthday = models.DateField(verbose_name="出生日期", null=True, blank=True)
    mobile = models.CharField(verbose_name="手机号码", null=True, blank=True, max_length=32)  # 唯一索引
    email = models.EmailField(verbose_name="邮箱", max_length=100, null=True, blank=True)
    gender = models.SmallIntegerField(verbose_name="性别", choices=GENDER_CHOICES, default=2)

    class Meta:
        verbose_name = "用户"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username


class VerifyCode(models.Model):
    """
    短信验证码，一般放到redis中
    """
    code = models.CharField(max_length=10, verbose_name="验证码")
    mobile = models.CharField(verbose_name="手机号码", unique=True, max_length=32)
    add_time = models.DateTimeField(default=datetime.now(), verbose_name="添加时间")

    class Meta:
        verbose_name = "短信验证码"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.code
